/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse;

import java.io.UnsupportedEncodingException;

/**
 *
 * @author Swang
 */
public class StringBytesTest {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String defaultEncoding = System.getProperty("file.encoding");
        String defaultLanguage = System.getProperty("user.language");
        System.out.println(defaultEncoding);
        System.out.println(defaultLanguage);
        String testStr = "中文";
        byte [] defaultBytes = testStr.getBytes();
        System.out.println("Default encoding:");
        StringBytesTest.printBytes(defaultBytes);

        byte [] gbkBytes = testStr.getBytes("GBK");
        System.out.println("GBK encoding:");
        StringBytesTest.printBytes(gbkBytes);
        
        byte [] isoBytes = testStr.getBytes("iso8859-1");
        System.out.println("ISO8859-1 encoding:");
        StringBytesTest.printBytes(isoBytes);
        
        System.out.println(new String(gbkBytes,"GBK"));
        System.out.println(new String(gbkBytes,"UTF8"));
    }
    
    public static void printBytes(byte[] array) {
        for(byte b : array) {
            System.out.println(b + " : " +Integer.toHexString(b));
        }
        System.out.println("--------------------------");
    }
}
